/**
 * Created by CHENJI5 on 7/14/2016.
 */
$(document).ready(function () {
    $(".oal-page-header-menu-notification-badge").popover();


    switchUnreadIndicator();

    $(".oal-notification-list-item-check").hide();
    $("#btn-cancel").bind("click",function(){
        $(".oal-notification-list-item-check").hide();
        $("#btn-cancel").hide();
    }).hide();

    $("#btn-delete").bind("click",function(){
        if($("#btn-cancel").is(":hidden")){
            $("#btn-cancel").show();
            $(".oal-notification-list-item-check").show();
        }else{
            var selectItem = $("input[type=checkbox]:checked").length;
            window.confirm("Are you sure to delete 3 selected notifications?")
        }

    });


    $(".oal-notification-list-item .row").bind("click", function () {
        $(this).next(".oal-notification-list-item-details").slideToggle("slow");
        $(this).parent(".oal-notification-list-item").removeClass("oal-notification-list-item-unread");
        $(this).find(".oal-notification-list-item-title").removeClass("oal-notification-list-item-title-unread");
    })
    $(".oal-notification-list-chat,.delete-icon,.star-icon").bind("click", function (event) {
        event.stopPropagation();
    })
    $(".mark-as-read,.mark-as-unread").on("click",function(event){
        if($(this).hasClass("mark-as-read")){
            $(this).addClass("mark-as-unread").removeClass("mark-as-read");
            $(this).parent().parent().parent().removeClass("oal-notification-list-item-unread");

        }else{
            $(this).removeClass("mark-as-unread").addClass("mark-as-read");
            $(this).parent().parent().parent().addClass("oal-notification-list-item-unread")
        }
        event.stopPropagation();
    })
    $(".delete-icon").bind("click", function () {
        $(this).parent().parent().parent().remove();
    })
    $(".oal-notification-list-chat").bind("click",function(){
        $("#btn_chat").click();
    })



    $(".oal-notification-list-chat").hide()
    $(".delete-icon").hide()
    $(".mark-as-read").hide()
    $(".mark-as-unread").hide()
    $(".oal-notification-list-item").bind("mouseover", function () {
        $(this).find(".oal-notification-list-chat").show();
        $(this).find(".delete-icon").show();
        $(this).find(".mark-as-read").show();
        $(this).find(".mark-as-unread").show();
    }).bind("mouseout", function () {
        $(this).find(".oal-notification-list-chat").hide();
        $(this).find(".delete-icon").hide();
        $(this).find(".mark-as-read").hide();
        $(this).find(".mark-as-unread").hide();
    })


    $(".oal-page-header-menu-notification-badge").bind("click",function(event){
        event.stopPropagation();
    })

    $(".oal-page-header-menu-notification").bind("mouseover",function(){

    })

});
function switchUnreadIndicator() {
    var notificationType = $(".oal-notification-list-item");
    notificationType.each(function () {
        if ($(this).hasClass("oal-notification-list-item-unread")) {
            $(this).find(".oal-notification-list-item-title").addClass("oal-notification-list-item-title-unread");
        }
        else {
            $(this).find(".oal-notification-list-item-title").removeClass("oal-notification-list-item-title-unread");
        }
    })


}